//
//  HomePageViewController.m
//  HSApp
//
//  Created by xc on 15/11/5.
//  Copyright © 2015年 xc. All rights reserved.
//

#import "HomePageViewController.h"

@interface HomePageViewController ()

@property (nonatomic, strong) UITableView *homeTableView;
@property (nonatomic, strong) AdAnimationView *adAnimationView;//滚动广告
@property (nonatomic, strong) CustomerHeadView *cHeadView;
@end

@implementation HomePageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = ViewBgColor;
    self.title = @"首页";
    
    if (!_adAnimationView) {
        _adAnimationView = [[AdAnimationView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 130)];
        _adAnimationView.delegate = self;
    }
    
    NSMutableArray *array = [[NSMutableArray alloc] init];
    AdAniMationModel *model1 = [[AdAniMationModel alloc] init];
    model1.imgUrl =@"http://pic2.ooopic.com/01/03/51/25b1OOOPIC19.jpg";
    [array addObject:model1];
    AdAniMationModel *model2 = [[AdAniMationModel alloc] init];
    model2.imgUrl =@"http://img.taopic.com/uploads/allimg/130501/240451-13050106450911.jpg";
    [array addObject:model2];
    AdAniMationModel *model3 = [[AdAniMationModel alloc] init];
    model3.imgUrl =@"http://pic2.ooopic.com/01/03/51/25b1OOOPIC19.jpg";
    [array addObject:model3];
    [_adAnimationView refreshShowWith:array];
    
    [self initheadView];
    [self.view addSubview:_cHeadView];

    [self inithomeTableView];
    [self.view addSubview:_homeTableView];
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


//初始化下单table
-(UITableView *)inithomeTableView
{
    if (_homeTableView != nil) {
        return _homeTableView;
    }
    
    CGRect rect = self.view.frame;
    rect.origin.x = 0.0;
    rect.origin.y = 104.0;
    rect.size.width = self.view.frame.size.width;
    rect.size.height = self.view.frame.size.height-104;
    
    self.homeTableView = [[UITableView alloc] initWithFrame:rect style:UITableViewStyleGrouped];
    _homeTableView.delegate = self;
    _homeTableView.dataSource = self;
    _homeTableView.backgroundColor = WhiteBgColor;
    self.automaticallyAdjustsScrollViewInsets = false;
    return _homeTableView;
}


- (UIView *)initheadView
{
    if (_cHeadView != nil) {
        return _cHeadView;
    }
    
    CGRect rect = self.view.frame;
    rect.origin.x = 0.0;
    rect.origin.y = 64.0;
    rect.size.width = self.view.frame.size.width;
    rect.size.height = 40;
    _cHeadView.backgroundColor = WhiteBgColor;
    _cHeadView = [[CustomerHeadView alloc] initWithFrame:rect];
    _cHeadView.delegate = self;
    return _cHeadView;
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

#pragma tableView delegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 5;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        return 130;
    }
    return 0.01;
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.01;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    if (section == 0) {

        return _adAnimationView;
    }
    return nil;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 100;
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellName = @"cellname";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellName];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.textLabel.text = @"测试";
    cell.textLabel.textColor = [UIColor colorWithRed:102.0/255.0 green:102.0/255.0 blue:102.0/255.0 alpha:1.0];
    cell.textLabel.font = [UIFont systemFontOfSize:15];
    return cell;

}
#pragma CustomerHeadDelegate 雇主头部view点击事件代理
- (void)headClick
{
    [UIView animateWithDuration:0.3 animations:^{
        _cHeadView.frame = CGRectMake(0, 64, SCREEN_WIDTH, 80);
        _homeTableView.frame = CGRectMake(0, 144, SCREEN_WIDTH, SCREEN_HEIGHT-144);
    } completion: ^(BOOL finish){

    }];


}

#pragma AdAnimationViewDelegate 轮播图点击事件代理
- (void)adHasSelect:(AdAniMationModel *)model
{
    
}


@end
